<template>
<div>
  <el-button type="primary" plain @click="dialogVisible = true;"
             style="position: absolute;left: 330px;top: 80px;">添加</el-button>
  <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="30%">
    <el-input placeholder="请输入出版社名称" v-model="publisheradd.name" style="width: 300px"></el-input><br><br>
    <el-input placeholder="请输入地区" v-model="publisheradd.site" style="width: 300px"></el-input><br><br>
    <el-input placeholder="请输入联系人" v-model="publisheradd.contact" style="width: 300px"></el-input><br><br>
    <el-input placeholder="请输入负责人" v-model="publisheradd.the" style="width: 300px"></el-input><br><br>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="add()">确 定</el-button>
  </span>
  </el-dialog>
  <div>
    <br>
    <br>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="出版社名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="site"
        label="地区"
        width="180">
      </el-table-column>
      <el-table-column
        prop="contact"
        label="联系人"
        width="180">
      </el-table-column>
      <el-table-column
        prop="the"
        label="负责人"
        width="180">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="dialogFormVisible=true;publisherupd=scope.row"></el-button>
          <el-button
            size="mini"
            type="danger" icon="el-icon-delete"
            @click="del(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      small
      layout="total,prev, pager, next"
      :page-size="pageSize"
      :total="total" @current-change="page">
    </el-pagination>

    <el-dialog title="纸质修改" :visible.sync="dialogFormVisible">
      <el-form :model="publisherupd">
        <el-form-item label="编号">
          <el-input v-model="publisherupd.id" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="名称" >
          <el-input v-model="publisherupd.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="地区" >
          <el-input v-model="publisherupd.site" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系人" >
          <el-input v-model="publisherupd.contact" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="负责人" >
          <el-input v-model="publisherupd.the" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="upd()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</div>
</template>

<script>
export default {
  name: "Publisher",
  data(){
    return{
      total: 0,
      pageSize: 6,
      tableData: [],
      publisheradd:{name:"",site:"",contact:"",the:""},
      publisherupd:{},
      dialogVisible:false,
      dialogFormVisible:false
    }
  },
  created() {
    this.find()
  },
  methods:{
    find(){
      this.$http.post("/backservice/publisher/findpage?pageNum=0&pageSize=" + this.pageSize).then(response => {
        console.log(response.userList)
        this.tableData = response.userList
        this.total = response.TotalNum
      })
    },
    add(){
      this.dialogVisible=false
      this.$http.post("/backservice/publisher/add",this.publisheradd).then(data=>{
        if (data>0){
          this.find()
          alert("添加成功")
        }else {
          alert("添加失败")
        }
      })
    },
    page(currentPage) {
      this.$http.post('/backservice/publisher/findpage?&pageNum=' + (currentPage - 1) + '&pageSize=' + this.pageSize)
        .then(response => {
          this.tableData = response.userList
        })
    },
    upd(){
      this.dialogFormVisible=false
      this.$http.post("/backservice/publisher/update",this.publisherupd).then(data=>{
        if (data>0){
          this.find()
          alert("修改成功")
        }else {
          alert("修改失败")
        }
      })
    },
    del(row){
      this.$http.post("/backservice/publisher/delete",{id:row.id}).then(data=>{
        if (data>0){
          this.find()
          alert("删除成功")
        }else {
          alert("删除失败")
        }
      })
    }


  }
}
</script>

<style scoped>

</style>
